<%--
 *  File:    LevelRule.jsp
 *  @Author: TendyHu 
 *  Date:    2010/10/08
 *  @Modifier: Jamesli 
 *  Date:    2011/01/07
 *
 *  Copyright (C) 2000 - 2011 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>


<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java"%>
<%@ page import="java.util.*"%>
<%@ page import="org.apache.log4j.Category"%>

<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom"%>

<% //--------------------------------------  setting logger --%>
<%
  	Category cat = Category.getInstance("jsp.LevelRule"); 
%>

<% //--------------------------------------  variant and initialization --%>
<%
	String strModuleName = "IMG";
  	String strTableName = "v_levelrule";
  	String privilegeCode = "ZA0926";
    String contextPath = request.getContextPath();
%>
<%
  	HashMap CurUserInfo = (HashMap)session.getAttribute("userinfo");
  	Integer nLevelRuleId = (Integer)CurUserInfo.get("levelruleid"); 	
%>

<% //--------------------------------------  include files list --%>
<%@ include file="/inc/Security.inc"%>
<%@ include file="/inc/PageDefault.inc"%>
<%@ include file="/inc/LocationDefault.inc"%>

<html>
<head>
<title>LevelRule</title>
<PageFlow:CheckPageFlow pageName="p_levelrule" />
<%@ include file="/inc/InitEdit.inc"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%= contextPath%>/css/<%= strLanguageCode %>/main.css"	type="text/css">
<script language="JavaScript" src="<%= contextPath%>/css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="<%= contextPath%>/js/ScriptLib.js"></script>
<%@ include file="/inc/SummaryDivision.inc"%>
<script>
parent.down.location.href = "Blank.jsp?<%= OvalTools.randomURL() %>";
function clickRow(id)
{
  parent.down.location.href = "Blank.jsp?<%= OvalTools.randomURL() %>";
  document.cform.levelruleid.value = id;
}

function page_new(){	
	var leveltype = document.cform.leveltype.value;
	parent.down.location.href = "LevelRuleEdit.jsp?<%= OvalTools.randomURL() %>&leveltype=" + leveltype;
}

function page_delete()
{
  var id = document.cform.levelruleid.value;
  
  if(isEmpty(id) || id == "-1")
    return;
    
   if(id == "<%=JspHelper.filterNull( nLevelRuleId )%>")
  {
    alert("<%= message.getMessageDesc("CAN_NOT_DEL_IT") %>");
    return;
  }
  var flag = confirm("<%= message.getMessageDesc("ARE_YOU_SURE_DEL") %>");
  if(!flag)
    return;
  document.cform.actionname.value = "delete";
  isRunning = true;
  document.cform.submit();
}

function page_edit()
{
  	var uid = document.cform.levelruleid.value;
  	if(isEmpty(uid)|| uid == "-1")
    	return;
	var leveltype = cform.leveltype.value;
  	parent.down.location.href = "LevelRuleEdit.jsp?<%= OvalTools.randomURL() %>&levelruleid=" + uid + "&leveltype=" + leveltype;
}

function page_summary(actionvalue,orderbyname)
{
  var editform = summaryPrepare(cform,actionvalue,orderbyname);
  var leveltype = cform.leveltype.value;
  var strleveltype = "";
  if(!isEmpty(leveltype)){
	strleveltype = "&leveltype=" + leveltype;
  }
  editform.action = "LevelRule.jsp?<%= OvalTools.randomURL() %>" + strleveltype;
  editform.target = "_self";
  isRunning = true;
  editform.submit();  
}

function page_relevelrule()
{
	var uid = document.cform.levelruleid.value;
  	if(isEmpty(uid) || uid == "-1")
    	return;
   
	document.cform.actionname.value = "relevelrule";
	cform.target = "_parent";
	isRunning = true;
	document.cform.submit();
}

</script>

<% //--------------------------------------  output variant from pageflow --%>
<%
  	Vector totalsummary = (Vector)pageContext.getAttribute("totalsummary");
  	if(totalsummary == null)
  	{
  		totalsummary = new Vector();
  	}
%>
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<% //--------------------------------------  hidden form variant --%>
<form name="cform" method="post" action="<%= contextPath%>/Dispatcher" target="_parent">
	<input type="hidden" name="pagename" value="p_levelrule"> 
	<input type="hidden" name="actionname">
	
<% //--------------------------------------  page location --%>
<%@ include file="/inc/PageLocation.inc"%>

<table width="100%" cellspacing="0" cellpadding="0" border="0">
	<tr>
		<td class="summary_top"></td>
	</tr>
	<tr>
		<td class="td-text" width="80">
			<font class="red"><%= label.getLabelName("L_LevelType") + label.getLabelName("L_Colon") %></font>
		</td>
		<td>
			<custom:select optionsName="leveltypes"	optionValueKey="leveltypeid" optionInnerTextKey="typename" property="leveltype" onchange="page_summary('search')" defaultValue="------------" defaultValueCost=""/>
		</td>
		<td>
		<table border="0" cellspacing="0" cellpadding="0">
			<%@ include file="/inc/SummarySearch.inc" %>
		</table>
		</td>
	</tr>
</table>

<table border="1" cellspacing="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" align="center" width="100%" cellpadding="0">

	<% //--------------------------------------  summary header --%>
	<tr class="deepblue-left">
		<td width="5%" class="title_center">&nbsp;</td>
		<td width="15%" class="title_center"><a	href="javascript:page_summary('orderby','levelcode')"><%= label.getLabelName("L_LevelCode") %></a></td>
		<td width="30%" class="title_center"><a	href="javascript:page_summary('orderby','levelname')"><%= label.getLabelName("L_LevelName") %></a></td>
		<td width="*" class="title_center"><a	href="javascript:page_summary('orderby','description')"><%= label.getLabelName("L_Description") %></a></td>
	</tr>

	<% //--------------------------------------  default value definition --%>
	<%
        Integer nDefaultLevelRuleId = new Integer(-1);               
        String strClassType = new String(); 
        boolean bHasChecked = false;
   	%>

	<% //--------------------------------------  loop results --%>
	<logic:iterate id="onerow" collection="<%= totalsummary %>" indexId="idx">

		<%
		HashMap levelRuleMap = (HashMap)pageContext.getAttribute("onerow"); 
        String strIsChecked = "";
            
        if((idx.intValue())%2 == 1){
        	strClassType = "td-listrom";             
        }else{                    
            strClassType = "none";
        }
        
       if(!bHasChecked)
        {
	        strIsChecked = "Checked";                       
            bHasChecked = true;
            nDefaultLevelRuleId = (Integer)(levelRuleMap.get("levelruleid"));            
        }                
  	%>

		<tr onMouseOver="this.className='tr-over'" onMouseOut="this.className='<%= strClassType %>'" onClick="javascript:radiotrue('radio<%=idx.intValue()%>');clickRow('<custom:write name="onerow" property="levelruleid"/>');" class="<%=JspHelper.filterNull( strClassType )%>">
			<td>
				<input id="radio<%=idx.intValue()%>" type="radio" name="levelruleids" value="<custom:write name="onerow" property="levelruleid"/>" class="normalradio" <%=strIsChecked%>>
			</td>
			<td><custom:write property="levelcode" name="onerow" nbsp="true"/></td>
			<td><custom:write property="levelname" name="onerow" nbsp="true"/></td>
			<td><custom:write property="description" name="onerow" nbsp="true"/></td>
		</tr>
	</logic:iterate>

	<% //--------------------------------------  default value --%>
	<input type="hidden" name="levelruleid"	value="<%=nDefaultLevelRuleId%>">

	<% //--------------------------------------  flipping page --%>
	<%@ include file="/inc/SummaryAction.inc"%>
</table>

<% //--------------------------------------  page operation button --%>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td class="summary_top"></td>
	</tr>
	<tr>
		<td class="td_center">
		<%
			Integer leveltype = (Integer)pageContext.getAttribute("leveltype");
			if(leveltype != null){
		%>
			<a onclick="page_new()"><custom:button type="1"	label="L_New" imgsrc="new.gif" border="0" style="width:60" /></a>
			<a onclick="page_edit()"><custom:button type="1" label="L_Edit"	imgsrc="edit.gif" border="0" style="width:60" /></a>
			<a onclick="page_delete()"><custom:button type="1" label="L_Delete"	imgsrc="delete.gif" border="0" style="width:60" /></a>
			<a onclick="page_relevelrule()"><custom:button type="1"	label="L_ReLevelRule" imgsrc="finish.gif" border="0" style="width:80"/></a>
		<%}else{ %>
			&nbsp;
		<%} %>
		</td>
	</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>